package com.demo.数据绑定底层演示;

import java.util.Date;

import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.validation.DataBinder;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.ServletRequestParameterPropertyValues;

public class TestServletDataBinder {
	
	public static void main(String[] args) {
		MyBean target = new MyBean();
		ServletRequestDataBinder dataBinder = new ServletRequestDataBinder(target);
		MockHttpServletRequest request = new MockHttpServletRequest();
		request.setParameter("a", "10");
		request.setParameter("b", "hello");
		request.setParameter("c", "1999/03/04");
		dataBinder.bind(new ServletRequestParameterPropertyValues(request));
		System.out.println(target);
	}

	static class MyBean {
		private int a;
		private String b;
		private Date c;
		public int getA() {
			return a;
		}
		public void setA(int a) {
			this.a = a;
		}
		public String getB() {
			return b;
		}
		public void setB(String b) {
			this.b = b;
		}
		public Date getC() {
			return c;
		}
		public void setC(Date c) {
			this.c = c;
		}
		@Override
		public String toString() {
			return "MyBean [a=" + a + ", b=" + b + ", c=" + c + "]";
		}
		
	}
	
}